package com.example.question.list.list1;

/**
 * @Date 2023-07-02
 * @Author Jonathan
 * @link { <a href="https://leetcode.cn/problems/delete-node-in-a-linked-list/">...</a> }
 */
public class Code02_237 {
    public static void main(String[] args) {

        int[] nums = new int[]{3, 1, 2, 5, 6, 4};
        ListNode node1 = List.createList(nums);
        ListNode node2 = node1.next;
        List.printLink(node1);
        Code02_237 code = new Code02_237();
        code.deleteNode(node2);
        List.printLink(node1);

    }


    /**
     * 借尸还魂
     */
    public void deleteNode(ListNode node) {
        ListNode cur = node;
        ListNode next = node.next;
        while (next.next != null) {
            cur.val = next.val;
            cur = cur.next;
            next = next.next;
        }
        cur.val = next.val;
        cur.next = null;
    }
}
